﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProjTemp.Desktop.Common.Module;
using Microsoft.Practices.Prism.Modularity;
using Microsoft.Practices.Prism.MefExtensions.Modularity;
using ProjTemp.Common.Logging;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.ServiceLocation;
using Mysoft.ServerMonitoring.OMKit.Infrastructure;
using System.ComponentModel.Composition;
using ProjTemp.Desktop.Common.Events;
using System.Windows;
using ProjTemp.Desktop.Common;
using System.Windows.Media;

namespace Mysoft.ServerMonitoring.OMKit.HomePage
{
    [ModuleExport(typeof(HomePageModule), InitializationMode = InitializationMode.WhenAvailable)]
    internal class HomePageModule : ModuleBase
    {
        [ImportingConstructor]
        public HomePageModule(ILogger logger, IRegionManager regionManager, IEventAggregator eventAggregator, IServiceLocator serviceLocator)
            : base(logger, regionManager, eventAggregator, serviceLocator)
        {
        }

        public override void Initialize()
        {
            var dict = new ResourceDictionary { Source = new Uri(StyleConst.IconsUriAddress) };
            var titleBarItem = new TitleBarItem(Guid.NewGuid().ToString(), 1, "主  页", "主  页", ViewTopics.HomePageTopic, (Visual)dict["appbar_home"]);
            this._eventAggregator.GetEvent<TitleBarItemsChangedEvent>().Publish(new TitleBarItemsChanged() { Action = NotifyTitleBarItemsChangedAction.Added, NewTitleBarItems = new List<TitleBarItem>() { titleBarItem } });
            this._regionManager.RegisterViewWithRegion(RegionNames.RightContentRegion, () => this._serviceLocator.GetInstance<HomePage.Views.HomePage>(ViewTopics.HomePageTopic));
        }
    }
}